<?php

var $phoneID ="";
var $sendMessage ="";



$ch = curl_init();
   
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");   
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);   
   
$data = array('accountType' => 'HOSTED_OR_GOOGLE',   
'Email' => '아이디@gmail.com',   
'Passwd' => '비번',   
'source'=>'test-1.0',   
'service'=>'ac2dm');

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);   
curl_setopt($ch, CURLOPT_POST, true);   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);   

$result = curl_exec($ch); 
$auth = substr(strstr($result, "Auth="), 5);  
$auth = substr($auth, 0, strlen($auth)-1); 
 
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");

srand((double)microtime()*1000000);
$collapse_key = rand(1,99);
$data = "registration_id=$phoneID"."&collapse_key=$collapse_key"."&data.msg=".urlencode($sendMessage);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
 
$headers = array( 
    "Content-Type: application/x-www-form-urlencoded", 
    "Content-Length: ".strlen($data), 
    "Authorization: GoogleLogin auth=$auth"
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result."\n";

curl_close($ch);
?>